package com.xinqi.modules.exam.utils;

import com.xinqi.common.base.response.R;
import com.xinqi.common.security.utils.UserHelp;
import com.xinqi.modules.course.clazz.client.ClassStudentClient;
import com.xinqi.modules.course.clazz.dto.rsp.ClassStudentResultDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * 学生帮助类
 *
 * @author linkai
 * @date 2023/11/27
 */
@Component
@RequiredArgsConstructor
public class StudentHelp {
    private final ClassStudentClient classStudentClient;

    public ClassStudentResultDTO getStudent(Long classId, Long userId) {
        R<ClassStudentResultDTO> rsp = classStudentClient.findVirtualClassStudentByClassIdAndUserId(classId, userId);
        return R.as(rsp, "主学生不存在");
    }

    public ClassStudentResultDTO getStudent(Long classId) {
        return getStudent(classId, UserHelp.userId());
    }

    public Long getStudentId(Long classId, Long userId) {
        R<ClassStudentResultDTO> rsp = classStudentClient.findVirtualClassStudentByClassIdAndUserId(classId, userId);
        return R.as(rsp, "主学生不存在").getStudentId();
    }

    public Long getStudentId(Long classId) {
        return getStudentId(classId, UserHelp.userId());
    }
}
